package LinkedListPackage2;

import LinkedListPackage.ListNode;

/**
 * @author Lzm
 * @version 1.0
 */
public class reverseList_ {

  public ListNode reverseList(ListNode head) {
    if (head == null){
      return null;
    }
    // 每次temp2指向temp后, 都令temp1 = temp2 , temp2 = temp2.next即可
    ListNode temp1 = null;
    ListNode temp2 = head;
    while(temp2 != null){
      ListNode temp = temp2.next;
      temp2.next = temp1;
      temp1 = temp2;
      temp2 = temp;
    }
    return temp1;
  }
}
